from appium import webdriver
from time import sleep
import logging
import logging.config
import sys

sys.path.append(r'..')
from common.get_yaml_data import get_yaml_data

logging.config.fileConfig(r'..\config\log_conf.ini')
logger = logging.getLogger()


def desired_caps():
    data = get_yaml_data(r'..\config\desired_caps.yml')
    desired_caps = {}
    desired_caps['platformName'] = data['platformName']
    desired_caps['platformVersion'] = data['platformVersion']
    desired_caps['deviceName'] = data['deviceName']
    desired_caps['app'] = data['app']
    desired_caps['appPackage'] = data['appPackage']
    desired_caps['appActivity'] = data['appActivity']
    desired_caps['noReset'] = data['noReset']

    driver = webdriver.Remote(f'http://{data["ip"]}:{data["port"]}/wd/hub', desired_caps)
    driver.implicitly_wait(10)  # 隐式等待
    sleep(3)
    logging.info('app start success ...')

    return driver


if __name__ == '__main__':
    driver = desired_caps()
